Skip to content

OCPBUGS-78995: Azure Machines: Accept explicit image ID#10712

Open
2uasimojo wants to merge 1 commit into
openshift:mainfrom
2uasimojo:OCPBUGS-78995/azure-mset-image-id
Open

OCPBUGS-78995: Azure Machines: Accept explicit image ID#10712
2uasimojo wants to merge 1 commit into
openshift:mainfrom
2uasimojo:OCPBUGS-78995/azure-mset-image-id

Conversation

@2uasimojo

@2uasimojo 2uasimojo commented Jul 24, 2026

Copy link
Copy Markdown
Member

Machine API operator is limited in its ability to discover an appropriate default image for Machine[Set]s where it is not specified. Under direct cluster management, the workaround is to specify it. This change facilitates doing that when under remote/fleet management, such as via hive, via the MachineSets() function.

It was already possible to supply an explicit marketplace image, but the paths for managed and gallery images were written with hardcoded path formats dependent on knowing things about architecture and HyperVGeneration, intended to be used day 0 by the installer itself, where the environment is controlled/known and additional discovery and validation is possible.

With this change, we add a path for MachineSets() to accept an arbitrary OS image resource identifier, which may represent a managed or gallery image. This is one part of a two-part solution that will provide hive users an escape hatch if they encounter this MAO defaulting limitation in environments where marketplace images are not available/appropriate.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected Azure image selection to honor explicitly provided non-marketplace image identifiers directly.
    • Improved robustness when trimming Azure image IDs by safely handling nonconforming formats, avoiding potential runtime errors.
    • Prevented custom image identifiers from being overridden by default installer images.

@openshift-ci-robot openshift-ci-robot added jira/severity-critical Referenced Jira bug's severity is critical for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Jul 24, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@2uasimojo: This pull request references Jira Issue OCPBUGS-78995, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Machine API operator is limited in its ability to discover an appropriate default image for Machine[Set]s where it is not specified. Under direct cluster management, the workaround is to specify it. This change facilitates doing that when under remote/fleet management, such as via hive, via the MachineSets() function.

It was already possible to supply an explicit marketplace image, but the paths for managed and gallery images were written with hardcoded URN formats dependent on knowing things about architecture and HyperVGenerationto, to be used in the context of day 0 by the installer itself, where the environment is controlled/known and additional discovery and validation is possible.

With this change, we add a path for MachineSets() to accept an arbitrary OS image URN, which may represent an image of any of the three supported types: marketplace (already handled by an existing case), managed, or gallery. This is one part of a two-part solution that will provide hive users an escape hatch if they encounter this MAO defaulting limitation in environments where marketplace images are not available/appropriate.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Azure image handling now preserves explicit subscription resource paths and prevents a slicing panic when image IDs lack the expected resource-group segment.

Changes

Azure image handling

Layer / File(s) Summary
Preserve explicit Azure resource paths
pkg/asset/machines/azure/azuremachines.go
capzImage returns /subscriptions/ image paths directly as the capz.Image ID.
Safely trim subscription prefixes
pkg/asset/machines/azure/machines.go
trimSubscriptionPrefix returns unchanged input when /resourceGroups/ is absent, avoiding a negative-index slice.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: Azure machines now accept explicit image IDs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed This PR only changes Azure production code; no Ginkgo test titles were added or modified in the touched files, so there are no unstable names to flag.
Test Structure And Quality ✅ Passed No Ginkgo tests were added or modified in the Azure package; the PR only hardens helper logic, so this checklist is not applicable.
Microshift Test Compatibility ✅ Passed Only two Azure helper files changed; no new Ginkgo It/Describe/Context/When tests were added, so MicroShift compatibility is not implicated.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo/e2e tests were added; the PR only changes Azure helper logic, so SNO compatibility is not implicated.
Topology-Aware Scheduling Compatibility ✅ Passed Changes only adjust Azure image ID parsing/selection; no pod scheduling, replicas, affinity, nodeSelector, taints, or topology logic was introduced.
Ote Binary Stdout Contract ✅ Passed No process-level code or stdout writes were added in the touched files; only helper logic changed, and there are no init/main/TestMain hooks in scope.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; only Azure image helper logic changed in pkg/asset/machines/azure.
No-Weak-Crypto ✅ Passed The touched Azure code only adjusts image-path handling and a bounds check; no weak crypto or secret comparison patterns are present.
Container-Privileges ✅ Passed Touched files only change Azure image ID handling; no container/K8s manifests or privileged settings were added.
No-Sensitive-Data-In-Logs ✅ Passed No new logging was added in the changed Azure paths; the only existing log is a generic instance-type Infof, and the new image-ID logic just returns values.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested review from jhixson74 and rna-afk July 24, 2026 15:17
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jhixson74 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/asset/machines/azure/azuremachines.go`:
- Around line 402-404: Add a unit test covering the image-selection logic in the
function containing the rhcosImg branch: verify explicit managed or gallery
image IDs populate capz.Image.ResourceID, while marketplace URNs continue
populating the marketplace-specific fields. Include the explicit non-marketplace
ID case and assert the returned image values to prevent regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 882480ed-f9c2-442f-a701-307bffddd62a

📥 Commits

Reviewing files that changed from the base of the PR and between d8f6a96 and cf09259.

📒 Files selected for processing (1)
  • pkg/asset/machines/azure/azuremachines.go

Comment on lines +402 to +404
case rhcosImg != "":
// An explicit non-marketplace URN was supplied. Use it as is.
return &capz.Image{ID: &rhcosImg}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add a regression test for explicit image IDs.

Please add or point to a unit test verifying that managed/gallery image IDs become ResourceID, while marketplace URNs still populate marketplace fields. This branch changes the image-selection contract and should guard against regressions.

As per coding guidelines, all Go code under pkg/ must have unit tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/asset/machines/azure/azuremachines.go` around lines 402 - 404, Add a unit
test covering the image-selection logic in the function containing the rhcosImg
branch: verify explicit managed or gallery image IDs populate
capz.Image.ResourceID, while marketplace URNs continue populating the
marketplace-specific fields. Include the explicit non-marketplace ID case and
assert the returned image values to prevent regressions.

Source: Coding guidelines

Comment thread pkg/asset/machines/azure/azuremachines.go Outdated
@2uasimojo
2uasimojo force-pushed the OCPBUGS-78995/azure-mset-image-id branch from cf09259 to f2e7e73 Compare July 24, 2026 15:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/asset/machines/azure/azuremachines.go`:
- Around line 402-404: Update the explicit resource-path branch in the rhcos
image handling to validate rhcosImg against an allow-list for a complete Azure
resource ID, including the subscription and /resourceGroups/ segments, before
constructing capz.Image. Reject malformed values such as /subscriptions/foo
safely, or ensure trimSubscriptionPrefix handles invalid input without slicing
at a negative index.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 9d65d4e3-5ab5-4bb8-b72a-17c68750cfd9

📥 Commits

Reviewing files that changed from the base of the PR and between cf09259 and f2e7e73.

📒 Files selected for processing (1)
  • pkg/asset/machines/azure/azuremachines.go

Comment thread pkg/asset/machines/azure/azuremachines.go
Machine API operator is limited in its ability to discover an
appropriate default image for Machine[Set]s where it is not specified.
Under direct cluster management, the workaround is to specify it. This
change facilitates doing that when under remote/fleet management, such
as via hive, via the `MachineSets()` function.

It was already possible to supply an explicit *marketplace* image, but
the paths for managed and gallery images were written with hardcoded
path formats dependent on knowing things about architecture and
HyperVGeneration, intended to be used day 0 by the installer itself,
where the environment is controlled/known and additional discovery and
validation is possible.

With this change, we add a path for `MachineSets()` to accept an
arbitrary OS image resource identifier, which may represent a managed or
gallery image. This is one part of a two-part solution that will provide
hive users an escape hatch if they encounter this MAO defaulting
limitation in environments where marketplace images are not
available/appropriate.
@2uasimojo
2uasimojo force-pushed the OCPBUGS-78995/azure-mset-image-id branch from f2e7e73 to 2a1abcb Compare July 24, 2026 16:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/asset/machines/azure/machines.go`:
- Around line 461-464: Add regression tests for the image-ID helper surrounding
the rgIndex validation, covering a valid subscription-scoped ID, an ID missing
“/resourceGroups/”, and empty input; assert the expected image result and ensure
malformed inputs do not panic. Place the tests with the existing unit tests for
the Azure machine helpers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 5a6bfbb2-d7d7-4ebd-a72c-e7cdeb1d60c4

📥 Commits

Reviewing files that changed from the base of the PR and between f2e7e73 and 2a1abcb.

📒 Files selected for processing (2)
  • pkg/asset/machines/azure/azuremachines.go
  • pkg/asset/machines/azure/machines.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/asset/machines/azure/azuremachines.go

Comment on lines +461 to +464
// Allow invalid inputs to fail downstream
if rgIndex < 0 {
return image
}

@coderabbitai coderabbitai Bot Jul 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add regression tests for valid and malformed image IDs.

This change fixes a panic path, but the modified helper has no visible unit tests. Cover a valid subscription-scoped ID, an ID without /resourceGroups/, and an empty input.

As per coding guidelines, all Go code under pkg/ must have unit tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/asset/machines/azure/machines.go` around lines 461 - 464, Add regression
tests for the image-ID helper surrounding the rgIndex validation, covering a
valid subscription-scoped ID, an ID missing “/resourceGroups/”, and empty input;
assert the expected image result and ensure malformed inputs do not panic. Place
the tests with the existing unit tests for the Azure machine helpers.

Source: Coding guidelines

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you point to an existing unit test that covers this function?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Azure machine-related Go tests =='
fd -t f -e go . pkg/asset/machines/azure | sort

echo
echo '== Direct trimSubscriptionPrefix calls =='
rg -n -C 3 '\btrimSubscriptionPrefix\s*\(' pkg/asset/machines/azure -g '*_test.go' || true

echo
echo '== mapiImage calls in tests (indirect coverage candidate) =='
rg -n -C 3 '\bmapiImage\s*\(' pkg/asset/machines/azure -g '*_test.go' || true

echo
echo '== Image ResourceID assertions in Azure machine tests =='
rg -n -C 3 '(ResourceID|resourceGroups)' pkg/asset/machines/azure -g '*_test.go' || true

Length of output: 1037


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Direct helper coverage in all Go tests =='
rg -n -C 3 '\btrimSubscriptionPrefix\s*\(' -g '*_test.go' . || true

echo
echo '== Indirect mapiImage coverage in all Go tests =='
rg -n -C 3 '\bmapiImage\s*\(' -g '*_test.go' . || true

echo
echo '== Tests covering the package or Azure resource-group image IDs =='
rg -n -C 3 '(pkg/asset/machines/azure|/resourceGroups/|ResourceID)' -g '*_test.go' . || true

Length of output: 3942


@2uasimojo, no—there is no existing unit test covering trimSubscriptionPrefix, directly or through mapiImage.

pkg/asset/machines/azure/ currently has no *_test.go files, and a repository-wide search found no test invocation of either helper. The closest match is pkg/types/azure/platform_test.go:TestSetBaseDomain, but it tests unrelated DNS zone parsing.

My original comment should have stated this more clearly: the requested tests would be new regression coverage, not an extension of an existing helper test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, imma leave it alone then, unless a human feels otherwise.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@2uasimojo, acknowledged. The panic fix is appropriately minimal; additional regression coverage can be added later if a human reviewer requests it.

@patrickdillon patrickdillon Jul 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this (I.e. what is the input/case where we hit this) change?

Generally the image function seems like a really good case for unit tests and should be easy to add with claude

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@2uasimojo

Copy link
Copy Markdown
Member Author

/test azure-ovn-marketplace-images

@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@2uasimojo: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/azure-ovn-marketplace-images 2a1abcb link false /test azure-ovn-marketplace-images

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/severity-critical Referenced Jira bug's severity is critical for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants